package org.tigris.subversion.svnant.commands;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.FileSet;
import org.tigris.subversion.svnant.SvnAntUtilities;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNStatus;
import org.tigris.subversion.svnclientadapter.SVNClientException;
import org.tigris.subversion.svnclientadapter.SVNStatusKind;
import org.tigris.subversion.svnclientadapter.utils.SVNStatusUtils;

public class ResourceSetSvnCommand extends SvnCommand
{
  private static final String MSG_FAILED_TO_CALCULATE_UNMANAGED = "Failed to calculate unmanaged entries.";
  private File dir;
  private File file;
  private boolean recurse;
  private boolean incfiledirs;
  private List<FileSet> filesets;
  private List<DirSet> dirsets;
  private SVNStatusKind unmanageddirs;
  private boolean scanunmanaged;

  ResourceSetSvnCommand(boolean paramBoolean1, boolean paramBoolean2)
  {
    this(paramBoolean1, paramBoolean2, false, null);
  }

  ResourceSetSvnCommand(boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, SVNStatusKind paramSVNStatusKind)
  {
    this.recurse = paramBoolean1;
    this.incfiledirs = paramBoolean2;
    this.unmanageddirs = paramSVNStatusKind;
    this.scanunmanaged = paramBoolean3;
    this.dir = null;
    this.file = null;
    this.filesets = new ArrayList();
    this.dirsets = new ArrayList();
  }

  private File[] collectDirectories(List<File> paramList)
  {
    ArrayList localArrayList = new ArrayList();
    if (this.dir != null)
      localArrayList.add(this.dir);
    Iterator localIterator = this.dirsets.iterator();
    while (localIterator.hasNext())
    {
      DirSet localDirSet = (DirSet)localIterator.next();
      collect(localArrayList, paramList, localDirSet);
    }
    return (File[])localArrayList.toArray(new File[localArrayList.size()]);
  }

  private File[] collectFiles(List<File> paramList)
  {
    ArrayList localArrayList = new ArrayList();
    if (this.file != null)
      localArrayList.add(this.file);
    Iterator localIterator = this.filesets.iterator();
    while (localIterator.hasNext())
    {
      FileSet localFileSet = (FileSet)localIterator.next();
      collect(localArrayList, paramList, localFileSet);
    }
    return (File[])localArrayList.toArray(new File[localArrayList.size()]);
  }

  private void collect(List<File> paramList1, List<File> paramList2, FileSet paramFileSet)
  {
    DirectoryScanner localDirectoryScanner = paramFileSet.getDirectoryScanner(getProject());
    File localFile1 = paramFileSet.getDir(getProject());
    File localFile2;
    if (this.incfiledirs)
    {
      String[] arrayOfString1 = localDirectoryScanner.getIncludedDirectories();
      for (String str : arrayOfString1)
      {
        localFile2 = new File(localFile1, str);
        collectUnmanaged(paramList2, localFile1, localFile2, false);
        paramList1.add(localFile2);
      }
    }
    String[] arrayOfString1 = localDirectoryScanner.getIncludedFiles();
    for (String str : arrayOfString1)
    {
      localFile2 = new File(localFile1, str);
      collectUnmanaged(paramList2, localFile1, localFile2.getParentFile(), false);
      paramList1.add(localFile2);
    }
  }

  private void collect(List<File> paramList1, List<File> paramList2, DirSet paramDirSet)
  {
    DirectoryScanner localDirectoryScanner = paramDirSet.getDirectoryScanner(getProject());
    File localFile1 = paramDirSet.getDir(getProject());
    String[] arrayOfString1 = localDirectoryScanner.getIncludedDirectories();
    for (String str : arrayOfString1)
    {
      File localFile2 = new File(localFile1, str);
      collectUnmanaged(paramList2, localFile1, localFile2, true);
      paramList1.add(localFile2);
    }
  }

  private void collectUnmanaged(List<File> paramList, File paramFile1, File paramFile2, boolean paramBoolean)
  {
    if (!this.scanunmanaged)
      return;
    try
    {
      Stack localStack = new Stack();
      for (ISVNStatus localISVNStatus = getClient().getSingleStatus(paramFile2); (paramFile2 != null) && (!paramFile2.equals(paramFile1)) && (this.unmanageddirs == null ? !SVNStatusUtils.isManaged(localISVNStatus) : localISVNStatus.getTextStatus() == this.unmanageddirs); localISVNStatus = getClient().getSingleStatus(paramFile2))
      {
        localStack.push(paramFile2);
        paramFile2 = paramFile2.getParentFile();
      }
      int i = paramBoolean ? 1 : 0;
      while (localStack.size() > i)
      {
        File localFile = (File)localStack.pop();
        if (!paramList.contains(localFile))
          paramList.add(localFile);
      }
    }
    catch (SVNClientException localSVNClientException)
    {
      throw ex(localSVNClientException, "Failed to calculate unmanaged entries.", new Object[0]);
    }
  }

  protected void validateAttributes()
  {
    SvnAntUtilities.attrsNotSet("file, dir, fileset, dirset", new Object[] { this.file, this.dir, this.filesets, this.dirsets });
    if (this.file != null)
      SvnAntUtilities.attrIsFile("file", this.file);
    if (this.dir != null)
      SvnAntUtilities.attrIsDirectory("dir", this.dir);
  }

  public final void execute()
  {
    handleBegin();
    ArrayList localArrayList = new ArrayList();
    File[] arrayOfFile1 = collectDirectories(localArrayList);
    File[] arrayOfFile2 = collectFiles(localArrayList);
    Object localObject = localArrayList.iterator();
    while (((Iterator)localObject).hasNext())
    {
      File localFile1 = (File)((Iterator)localObject).next();
      handleUnmanaged(localFile1);
    }
    for (File localFile2 : arrayOfFile1)
      handleDir(localFile2, this.recurse);
    for (File localFile2 : arrayOfFile2)
    {
      if (!localFile2.isDirectory())
        continue;
      handleDir(localFile2, false);
    }
    for (File localFile2 : arrayOfFile2)
    {
      if (localFile2.isDirectory())
        continue;
      handleFile(localFile2);
    }
    handleEnd();
  }

  protected void handleBegin()
  {
  }

  protected void handleUnmanaged(File paramFile)
  {
  }

  protected void handleDir(File paramFile, boolean paramBoolean)
  {
  }

  protected void handleFile(File paramFile)
  {
  }

  protected void handleEnd()
  {
  }

  public void setFile(File paramFile)
  {
    this.file = paramFile;
  }

  public void setDir(File paramFile)
  {
    this.dir = paramFile;
  }

  protected void setRecurse(boolean paramBoolean)
  {
    this.recurse = paramBoolean;
  }

  public void addFileset(FileSet paramFileSet)
  {
    this.filesets.add(paramFileSet);
  }

  public void add(FileSet paramFileSet)
  {
    this.filesets.add(paramFileSet);
  }

  public void addDirset(DirSet paramDirSet)
  {
    this.dirsets.add(paramDirSet);
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.commands.ResourceSetSvnCommand
 * JD-Core Version:    0.6.0
 */